<template>
  <div>
    <el-dialog :visible.sync="showAdd" title="添加模板" width="40%">
      <div>
        <p style="margin-bottom: 10px"> 模板名称<span style="color: #ce0e0f">*</span></p>
        <el-input v-model="data.templateName" size="small" placeholder="请输入模板名称"></el-input>
      </div>
      <div style="margin-top: 15px">
        <p style="margin-bottom: 10px"> 总分计算方式<span style="color: #ce0e0f">*</span></p>
        <el-radio v-model="data.type" label="1">问题项分数之和</el-radio>
        <el-radio v-model="data.type" label="2">巡查项分数之和</el-radio>
        <el-radio v-model="data.type" label="3">固定分值</el-radio>
        <el-input-number v-model="data.score" size="small" :max="100"  :min="0"></el-input-number>
      </div>
      <span slot="footer">
        <el-button size="small" style="color: #eeeeee;width: 80px" @click="comfirm">确 认</el-button>
        <el-button size="small" style="background:#fff;border:1px solid #eeeeee;width: 80px"
                   @click="showAdd=false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "addPatrol",
  data() {
    return {
      showAdd: false,
      data: {
        templateName: "",
        type: "1",
        score: 100,
      }
    }
  },
  methods: {
    handleOpen() {
      this.showAdd = true
      this.data = this.$options.data().data
    },
    comfirm() {
      let typeName = ""
      switch (this.data.type) {
        case '1':
          typeName = '问题项分数之和';
          break;
        case '2':
          typeName = '巡查项分数之和';
          break;
        case '3':
          typeName = '固定分值';
          break;
      }
      const data = this.data
      data.typeName = typeName
      this.$api.patrolAddPatrolTemplateDto(data).then(res => {
        if (res == 1) {
          this.$message.success('添加成功！')
          this.showAdd = false
          this.$emit('addStatus', 1);
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
/deep/ .el-radio__input.is-checked + .el-radio__label {
  color: #303e9d;
}

/deep/ .el-radio__input.is-checked .el-radio__inner {
  color: #303e9d;
  background-color: #303e9d;
}
</style>